<template>
  <div>
    <van-goods-action>
      <van-goods-action-icon icon="shop-o" text="店铺" @click="onClickIcon" />
      <van-goods-action-icon icon="bag-o" text="购物车" @click="onClickIcon" />
      <van-goods-action-button
        class="button"
        type="danger"
        text="加入购物车"
        color="#f9bc20"
        @click="onClickButton"
      />
    </van-goods-action>
  </div>
</template>

<script>
import Vue from "vue";
import { GoodsAction, GoodsActionIcon, GoodsActionButton } from "vant";

Vue.use(GoodsAction);
Vue.use(GoodsActionButton);
Vue.use(GoodsActionIcon);
import { Toast } from "vant";
import axios from "axios";

export default {
  name: "detfooter",
  data() {
    return {
      obj: JSON.parse(this.$route.query.obj),
      arr:[],
      count: 1,
      goodsName: "",
      goodsPrice: "",
      goodsImg: "",
      goodsColor: "",
    };
  },
  methods: {
    onClickIcon() {
      Toast("点击图标");
    },
    onClickButton() {
      Toast("加入购物车");
      // let id = this.obj
      //  this.$router.push({path:"/cart",query:{cart:id.goodsId}})
      let res = this.arr;
      this.$router.push({ path: "/cart" });
      axios({
        url: "/carts",
        method: "post",
        data: {
           "goodsId":res.goodsId,
           "goodsName":this.goodsName,
           "goodsPrice":this.goodsPrice,
           "goodsImg":this.goodsImg,
           "goodsCount":this.count,
           "goodsColor":this.goodsColor,
           "username":""
        },
      });
    },
  },
  created() {
    // console.log("nnnn");
    let id = this.obj.goodsId;
    axios({
      url: "/List",
      method: "get",
      params: {
        goodsId: id,
      },
    }).then((res) => {
      // console.log("接收", res.data);
      // console.log("发送", id);

      res.data.map((item) => {
        if (item.goodsId == id) {
          // console.log("我才是你要的数据" + item);
          this.arr.push(item);
          // console.log("Size", item.goodsSize);
          // console.log("arr", this.arr);
          // this.arr = item;
          // console.log(item);
          // console.log(this.arr);
          this.goodsName = item.goodsName;
          this.goodsPrice = item.goodsPrice;
          this.goodsImg = item.goodsImg;
          this.goodsColor = item.goodsColor;
        }
      });
    });
  },
};
</script>

<style scoped>
.button {
  width: 60%;
  border-radius: 0rem;
  background-color: orange;
}
</style>